<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Leave_management extends CI_Controller {

 
	function __construct()
	{
		parent::__construct();
		
		// check if user logged in 
		if (!$this->ion_auth->logged_in())
	  	{
			redirect('auth/login');
	  	}		
		$this->load->library('form_validation');
		$this->load->model('founder/leave_management_model');		
	}

function index()
   {
	   	$data['all_leave'] = $this->leave_management_model->get_all_leave();
	   	$meta['page_title'] = "Leave Management";	   
	  	$this->load->view('common/header',$meta);
		$this->load->view('founder/leave-management',$data);
		$this->load->view('common/footer');
   }
   
   function edit_leave_status($id)
   {
	 $data['user'] = $this->leave_management_model->get_leave_by_id($id);
	 $this->load->view('founder/leave-status',$data);		
   }

	function grant_leave()
	{
		$this->form_validation->set_rules('status', 'Status', 'required');
		
		if ($this->form_validation->run() == FALSE)
		{
			echo "no";
			$this->load->view('myform');
		}
		else
		{						
			$data = array(
			'status' => $this->input->post('status'),		
			);
			
			$check = array(			
			'id' => $this->input->post('id') 
			);
						
			$result = $this->leave_management_model->grant_leave($data,$check);
			
			redirect('founder/leave_management');
			/*$data['message'] = $result;
			$this->load->view('common/header');
			$this->load->view('founder/leave-management',$data);
			$this->load->view('common/header');*/
			
		}
	}
}
	
	?>